package com.pb.wkflow.core.service;

import com.pb.wkflow.core.entity.ActHiCommentEntity;
import com.pb.wkflow.core.entity.ActHiTaskEntity;
import org.camunda.bpm.engine.history.HistoricActivityInstance;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.history.HistoricTaskInstance;
import org.camunda.bpm.engine.history.HistoricVariableInstance;
import org.camunda.bpm.engine.runtime.ActivityInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 流程实例服务
 * @author 苗益辉
 * @date 2022/9/23 10:39
 */
public interface WorkflowInstanceService {

    /**
     * 查询流程实例
     * @param processInstanceId 流程实例id
     * @return ProcessInstance
     */
    ProcessInstance findByProcessInstanceId(String processInstanceId);

    /**
     * 设置流程变量
     * @param processInstanceId 流程实例id
     * @param variables 流程变量
     */
    void setVariables(String processInstanceId, Map<String, Object> variables);

    /**
     * 删除流程实例
     * @param processInstanceIds 流程ids
     */
    void deleteProcessInstance(List<String> processInstanceIds);

    /**
     * 删除历史流程实例
     * @param processInstances 流程ids
     */
    void deleteHistoryProcessInstance(List<String> processInstances);

    /**
     * 查询历史任务节点实例
     * @param processInstanceId 流程id
     * @return List<HistoricTaskInstance>
     */
    List<HistoricTaskInstance> queryHistoryTaskInstance(String processInstanceId);

    /**
     * 查询第一个历史任务节点实例
     * @param processInstanceId 流程id
     * @return List<HistoricTaskInstance>
     */
    List<HistoricTaskInstance> queryFirstHistoryTaskInstance(String processInstanceId);

    /**
     * 查询历史活动节点实例
     * @param processInstanceId 流程id
     * @return List<HistoricActivityInstance>
     */
    List<HistoricActivityInstance> queryHistoryServiceActivityInstance(String processInstanceId);

    /**
     * 查询历史活动节点实例，在时间之后
     * @param processInstanceId 流程id
     * @param startTime 时间
     * @return List<HistoricActivityInstance>
     */
    List<HistoricActivityInstance> queryHistoryServiceActivityInstanceAfter(String processInstanceId, Date startTime);

    /**
     * 查询历史活动节点数量
     * @param processInstanceId 流程id
     * @return Integer
     */
    Long countHistoryServiceActivityInstance(String processInstanceId);

    /**
     * 查询流程变量
     * @param processInstanceId 流程id
     * @return List<HistoricVariableInstance>
     */
    List<HistoricVariableInstance> queryHistoryVariableInstance(String processInstanceId);

    /**
     * 查询流程实例
     * @param processInstanceId 流程id
     * @return HistoricProcessInstance
     */
    HistoricProcessInstance queryHistoryProcessInstance(String processInstanceId);

    /**
     * 查询完成的任务
     * @param processInstanceId 流程id
     * @return HistoricTaskInstance
     */
    List<HistoricTaskInstance> queryFinishTaskInstance(String processInstanceId);

    /**
     * 查询子流程实例
     * @param processInstanceId 流程id
     * @return List<HistoricProcessInstance>
     */
    List<HistoricProcessInstance> querySubHistoryProcessInstance(String processInstanceId);

    /**
     * 根据流程实例id批量查询提交意见
     * @param processInstanceId 流程实例id
     * @return Map<String, List<ActHiCommentEntity>>
     */
    Map<String, List<ActHiCommentEntity>> findCommentsByProcessInstanceId(String processInstanceId);

    /**
     * 获取活动的节点
     * @param processInstanceId 流程实例id
     * @return ActivityInstance
     */
    ActivityInstance findActivityInstance(String processInstanceId);

    /**
     * 根据流程实例id查询历史任务
     * @param processInstanceId 流程实例id
     * @return List<ActHiTaskEntity>
     */
    List<ActHiTaskEntity> findTaskListByProcessInstanceId(String processInstanceId);

    /**
     * 未结束的流程实例数量
     * @param procDefineKey procDefineKey
     * @return int
     */
    int isActiveProcInstance(String procDefineKey);
}
